package asteroids.model.programs.parsing.expressions;

import java.util.Map;

import asteroids.model.CollisionObject;
import asteroids.model.Ship;

public class And extends LogicalExpression {

	public And(E left, E right) {
		super(left, right);
	}
	@Override
	public Object getContent(Map<String,E> map, CollisionObject givenCollisionObject){
		try{
			if(getExpression1().getContent(map, givenCollisionObject) instanceof Boolean 
					&& getExpression2().getContent(map, givenCollisionObject) instanceof Boolean){
				return ((boolean)getExpression1().getContent(map, givenCollisionObject) && (boolean)getExpression2().getContent(map, givenCollisionObject));

			}
			if(givenCollisionObject.isShip()){
				Ship ship = (Ship)givenCollisionObject;
				ship.getProgram().setMistake();
			}
			System.out.println("There is something wrong with you're program, please re-enter a new one.");
			return null;
		}
		catch(NullPointerException exc){
			if(givenCollisionObject.isShip()){
				Ship ship = (Ship)givenCollisionObject;
				ship.getProgram().setMistake();
			}
			System.out.println("There is something wrong with you're program, please re-enter a new one.");
			return null;
		}

	}

}
